package cn.gok.homework;

import java.util.Scanner;

public class Person {
    private String name;
    private String sex;
    private int age;
    private Boolean ifMarried;
    public static boolean marryWith(Person p1,Person p2){
        if(p1.ifMarried==false&&p2.ifMarried==false){
            if(!p1.sex.equals(p2.sex)) {
                if(p1.sex.equals("男")){
                    if(p1.age>=21&&p2.age>=19){
                        return true;
                    }
                }else {
                    if(p2.age>=21&&p1.age>=19){
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public void study(String school){
        System.out.println(name+"在"+school+"学习");
    }

    public static void main(String[] args) {
        Person p1=new Person("小明","男",21,false);
        Person p2=new Person("小红","女",20,false){
            @Override
            public void study(String school) {
                System.out.println("请输入已经学习的年份：");
                int years= new Scanner(System.in).nextInt();
                System.out.println(getName()+"在"+school+"学习了"+years+"年");
            }
        };
        if(Person.marryWith(p1,p2)){
            System.out.println("恭喜"+p1.name+"和"+p2.name+"成功结为夫妻");
        }
        p2.study("斯科拉大学");
    }
    public Person(String name, String sex, int age, Boolean ifMarried) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.ifMarried = ifMarried;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Boolean getIfMarried() {
        return ifMarried;
    }

    public void setIfMarried(Boolean ifMarried) {
        this.ifMarried = ifMarried;
    }


}